﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
                    xmlns:conv="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Converters"
                    xmlns:common="clr-namespace:Tum.PDE.ToolFramework.Modeling.Visualization.Controls.Common"
                    xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/AvalonDock;component/Resources/Brushes.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/AvalonDock;component/Themes/aero.normalcolor.xaml"/>        
    </ResourceDictionary.MergedDictionaries>

    <conv:MenuIconConverter x:Key="MenuIconUrlConv"/>

    <!-- 
    
    Partially from http://blogs.intuidev.com/post/2010/02/15/WPF-TabControl-series-Part-4-Closeable-TabItems.aspx
    Partially from AvalonDock
    
    -->
    
    <!-- Color of the border around the scrollbar-thumb -->
    <SolidColorBrush x:Key="LineButtonBorderBrush" Color="#FF8693BD"/>

    <!-- The background color of the TabItems popup-menu -->
    <LinearGradientBrush x:Key="TabItemMenuBackcolor" StartPoint="0,0" EndPoint="1,1">
        <GradientStop Offset="0" Color="White"/>
        <GradientStop Offset="1" Color="#EEE"/>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="MenuItem_ForegroundBrush"
                       Color="#333"/>
    <SolidColorBrush x:Key="MenuItem_DisabledForegroundBrush" 
                       Color="#AAA"/>
    <SolidColorBrush x:Key="MenuItem_DisabledBackgroundBrush" 
                       Color="#1555"/>
    <SolidColorBrush x:Key="TabItem_TextBrush_Selected" Color="#0D3288" />
    
    <!-- 
         The style for the MenuItem that represents the clickable portion
         for opening the sub-menu that itself will contain the list of
         TabItems.         
      -->
    <Style x:Key="TabMenuButtonStyle" TargetType="{x:Type MenuItem}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type MenuItem}">
                    <Border Name="ButtonBorder" Width="16" Height="16"
                         Background="Transparent" Margin="2"
						    BorderThickness="1"
						    Opacity="0.8">
                        <Grid>
                            <Image x:Name="ShowContextMenuIcon" VerticalAlignment="Center" HorizontalAlignment="Center" 
                                   Source="pack://application:,,,/AvalonDock;component/Resources/Images/PinMenu.png"
                                   Width="13" Style="{StaticResource DefaultIconStyle}"/>
                            <!--
                            <ContentPresenter ContentSource="Header" 
                                          Content="{StaticResource TabMenuButtonPath}"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch"/>-->
                            <Popup Name="Popup"
                               Placement="Bottom"
                               IsOpen="{TemplateBinding IsSubmenuOpen}"
                               AllowsTransparency="True" 
                               Focusable="False"
                               PopupAnimation="Fade">
                                <!-- 
                              Since we override the ControlTemplate, we're also responsible
                              for drawing stuff like the shadow around the popup-menu.
                              
                              Here, I'll use a Chrome that's provided in the Aero assembly. 
                              Note that, in order to use this (that is, the namespace defined
                              at the very top of this window), a reference to 
                              PresentationFramework.Aero is required.
                           -->
                                <mwt:SystemDropShadowChrome Color="#71000000" 
                                                       CornerRadius="1"
                                                       Margin="0,0,8,8"
                                                       SnapsToDevicePixels="True">
                                    <Border Name="SubmenuBorder"
                                   Margin="1"
                                   SnapsToDevicePixels="True"
                                   BorderBrush="{StaticResource LineButtonBorderBrush}" 
                                   Background="{StaticResource TabItemMenuBackcolor}" 
                                   CornerRadius="1" 
                                   BorderThickness="1">
                                        <StackPanel 
                                    IsItemsHost="True" 
                                    KeyboardNavigation.DirectionalNavigation="Cycle" />
                                    </Border>
                                </mwt:SystemDropShadowChrome>
                            </Popup>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsHighlighted" Value="true">
                            <Setter TargetName="ButtonBorder" Property="BorderBrush" 
                                Value="#FF3299FF" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- The style for MenuItems that represent TabItems -->
    <Style x:Key="TabMenuItem" TargetType="{x:Type MenuItem}">
        <!-- 
            In order to not further pollute the sample with more
            ControlTemplates, I'll stick with simply overriding
            the HilightBrushKey for the hovered MenuItem.
            Poor man's Style. :-)
         -->
        <Style.Resources>
            <LinearGradientBrush    
                  x:Key="{x:Static SystemColors.HighlightBrushKey}"
                  StartPoint="0.5,0" EndPoint="0.5,1">
                <GradientStop Color="#FFFFD5A0" Offset="0.3"/>
                <GradientStop Color="#FFEFA335" Offset="0.51"/>
                <GradientStop Color="#FFFFC14A" Offset="0.986"/>
            </LinearGradientBrush>
        </Style.Resources>

        <Setter Property="Icon" Value="{Binding ImageSource, Mode=OneWay, Converter={StaticResource MenuIconUrlConv}}"/>
        
        <!-- This will help us bind to the Header of a TabItem -->
        <!--<Setter Property="Header" Value="{Binding Path=Header}" />-->
        <Setter Property="Header">
            <Setter.Value>
                <TextBlock Text="{Binding Path=Title, Mode=OneWay}"/>
            </Setter.Value>
        </Setter>
        <!-- 
            In order for MenuItems to support the IsEnabled state of a TabItem,
            we simply bind the IsEnabled property of the MenuItem to that of the
            TabItem.
            This way, a disabled TabItem will not be selectable via the Menu.
         -->
        <Setter Property="IsEnabled" Value="{Binding Path=IsEnabled}" />
        <!-- 
            By making the MenuItems checkable AND binding the IsChecked
            property to the IsSelected property of the TabItems, we'll 
            efficiently allow to pick the selected TabItem from the Menu
            with a simple two-way binding.
         -->
        <!--<Setter Property="IsCheckable" Value="{Binding Path=IsEnabled}" />-->
        <!--<Setter Property="IsChecked" Value="{Binding Path=IsSelected, Mode=TwoWay}" />-->
        <Setter Property="Foreground" Value="{StaticResource MenuItem_ForegroundBrush}"/>
        <Style.Triggers>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Foreground"
                       Value="{StaticResource TabItem_TextBrush_Selected}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" 
                       Value="{StaticResource MenuItem_DisabledForegroundBrush}"/>
                <Setter Property="Background"
                                Value="{StaticResource MenuItem_DisabledBackgroundBrush}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <SolidColorBrush x:Key="DefaultBackgroundBrush" Color="#E9ECFA"/>
    <LinearGradientBrush x:Key="DocumentHeaderBackground" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#FFECF5FC" Offset="0" />
        <GradientStop Color="#FF98B4D2" Offset="1" />
    </LinearGradientBrush>
    <SolidColorBrush  x:Key="DocumentHeaderForeground"  Color="{x:Static SystemColors.WindowTextColor}"/>
    <LinearGradientBrush x:Key="DocumentHeaderBackgroundSelected" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#FFFCFDFE" Offset="0" />
        <GradientStop Color="#FFD2E6FA" Offset="1" />
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="DocumentHeaderBackgroundMouseOver" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#FFF7FCFE" Offset="0" />
        <GradientStop Color="#FF81CFF1" Offset="1" />
    </LinearGradientBrush>


    <Style TargetType="{x:Type common:TabItemAvalonDock}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type common:TabItemAvalonDock}">
                    <Border 
						x:Name="PART_DragArea" 
						BorderBrush="{StaticResource ManagedContentTabControlNormalBorderBrush}"
                        Margin="0,0,-10,0"
						SnapsToDevicePixels="True">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="20"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <!--This image with width=0 is required to connect the icon visual to the presentation source,
                                without this navigatorwindow won't work-->
                            <!--<Image Source="{TemplateBinding Icon}" Width="0"/>-->
                            <Path Data="M 20,0.5 Q 16,0.5 10,10 Q 5,19.5 0,19.5 L 20,19.5"
                                x:Name="tabItemIntPathBackground"  
                                  Fill="{DynamicResource DocumentHeaderBackground}"/>
                            <Path 
                                x:Name="tabItemIntPathBorder"  
                                Stroke="{StaticResource ManagedContentTabControlNormalBorderBrush}"
                                Data="M 20,0.5 Q 16,0.5 10,10 Q 5,19.5 0, 19.5"/>
                            <Border
                                    x:Name="tabItemIntBorder"
                                    Grid.Column="1"
                                    BorderThickness="0,1,1,0"
                                    Margin="-0.5,0,0,0"
                                    CornerRadius="0,3,0,0"
                                    BorderBrush="{StaticResource ManagedContentTabControlNormalBorderBrush}"
                                    Background="{DynamicResource DocumentHeaderBackground}"
                                >
                                <StackPanel Orientation="Horizontal" 
                                            Margin="5,0,4,0">

                                    <Image Grid.Column="0" Margin="0,0,3,0" x:Name="headerImage" Source="{Binding Path=ImageSource, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" Visibility="Hidden"/>
                                    <TextBlock Grid.Column="1" Text="{Binding Path=Title, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"/>
                                
                                    <Image  x:Name="PART_LockedIcon" Margin="2,0,0,0" Visibility="Collapsed" Source="pack://application:,,,/AvalonDock;component/resources/Images/Locked.png" Width="6" Style="{StaticResource DefaultIconStyle}"/>
                                </StackPanel>
                            </Border>
                        </Grid>

                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasImage" Value="True">
                            <Setter TargetName="headerImage" Property="Visibility" Value="Visible"/>
                        </Trigger>

                        <Trigger Property="Selector.IsSelected" Value="True">
                            <Setter Property="Background" 
                                    TargetName="tabItemIntBorder" 
                                    Value="{DynamicResource DocumentHeaderBackgroundSelected}"
                                    />
                            <Setter Property="Fill" 
                                    TargetName="tabItemIntPathBackground" 
                                    Value="{DynamicResource DocumentHeaderBackgroundSelected}"
                                    />
                            <Setter Property="BorderBrush" TargetName="tabItemIntBorder" Value="#FFC1D2EE"/>
                            <Setter Property="Stroke" TargetName="tabItemIntPathBorder" Value="#FFC1D2EE"/>
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" SourceName="tabItemIntBorder" Value="True"/>
                                <Condition Property="Selector.IsSelected" Value="False"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" 
                                    TargetName="tabItemIntBorder" 
                                    Value="{DynamicResource DocumentHeaderBackgroundMouseOver}"
                                    />
                            <Setter Property="Fill" 
                                    TargetName="tabItemIntPathBackground" 
                                    Value="{DynamicResource DocumentHeaderBackgroundMouseOver}"
                                    />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style  TargetType="{x:Type common:TabControlAvalonDock}">
        <Setter Property="Background" Value="{StaticResource DefaultBackgroundBrush}"/>
        <Setter Property="Focusable" Value="False"/>
        <!--<Setter Property="ItemContainerStyle" Value="{StaticResource TabItemAvalonDock}"/>-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type common:TabControlAvalonDock}">
                    <Border 
                        Focusable="False"
                        Background="{TemplateBinding Background}"
                        >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20" x:Name="rowDefinitionHeader"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            
                            <Border x:Name="PART_Header" 
							    Grid.Row="0" 
							    Focusable="False" 
							    BorderThickness="1,1,1,0">
                                <DockPanel LastChildFill="True">
                                    
                                    <Button DockPanel.Dock="Right" Width="18" Height="18" Style="{StaticResource PaneHeaderCommandStyle}" 
                                            Command="{Binding Path=CloseCommand, RelativeSource={RelativeSource AncestorType={x:Type common:TabControlAvalonDock}}}">
                                        <Image Source="pack://application:,,,/AvalonDock;component/Resources/Images/PinClose.png" Width="13" Style="{StaticResource DefaultIconStyle}"/>
                                    </Button>
                                    <!--
                                    <Button x:Name="PART_ShowContextMenuButton" DockPanel.Dock="Right" Width="18" Height="18" Style="{StaticResource PaneHeaderCommandStyle}">
                                        <Image x:Name="ShowContextMenuIcon" Source="pack://application:,,,/AvalonDock;component/Resources/Images/PinMenu.png" Width="13" Style="{StaticResource DefaultIconStyle}"/>
                                    </Button>-->
                                    <!--
                                    <Menu Background="Transparent" DockPanel.Dock="Right" Width="20" Height="20">
                                        <MenuItem Style="{StaticResource TabMenuButtonStyle}"
                                           ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type common:TabControlAvalonDock}}, Path=TabItems, Mode=OneWay}"
                                           ItemContainerStyle="{StaticResource TabMenuItem}">
                                        </MenuItem>
                                    </Menu>-->

                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <!-- The TabItems (resp. the TabPanel) will appear here -->
                                            <ColumnDefinition Width="*"/>
                                            <!-- The ScrollViewer controls will appear here -->
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <ScrollViewer Grid.Row="0" Grid.RowSpan="2" VerticalScrollBarVisibility="Disabled" CanContentScroll="True" 
                                            HorizontalScrollBarVisibility="Hidden" IsDeferredScrollingEnabled="False" SnapsToDevicePixels="True"
                                            Name="svTP" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch">

                                            <common:ScrollableTabPanel x:Name="PART_ScrollContentPresenter" Panel.ZIndex="1" Margin="0,2,0,0"
                                                IsItemsHost="True" RightOverflowMargin="4" LineScrollPixelCount="100" KeyboardNavigation.TabIndex="1"
                                                Background="Transparent"/>
                                        </ScrollViewer>
                                        <StackPanel Grid.Row="1" Grid.Column="3" Orientation="Horizontal">
                                            <!-- 
                                 The two RepeatButtons below will actually provide the scroll-
                                 functionality for the TabItems. Since the ScrollableTabPanel
                                 does not implements PageLeft/PageRight, LineLeft/LineRight
                                 are used.
                              -->
                                            <RepeatButton x:Name="cmdScrollLeft" Focusable="False" Background="Transparent" BorderBrush="Transparent" BorderThickness="0"
                                                CommandTarget="{Binding ElementName=svTP}" Command="ScrollBar.LineLeftCommand"
                                                Padding="0"
                                                IsEnabled="{Binding ElementName=PART_ScrollContentPresenter, Path=CanScrollLeft}">
                                                <Image Source="/Tum.PDE.ToolFramework.Images;component/Common/PinMenuLeft.png" Width="13" Style="{StaticResource DefaultIconStyle}"/>
                                            </RepeatButton>
                                            <RepeatButton x:Name="cmdScrollRight" Focusable="False" Background="Transparent" BorderBrush="Transparent" BorderThickness="0"
                                                CommandTarget="{Binding ElementName=svTP}" Command="ScrollBar.LineRightCommand"
                                                          Padding="0"
                                                IsEnabled="{Binding ElementName=PART_ScrollContentPresenter, Path=CanScrollRight}">
                                                <Image Source="/Tum.PDE.ToolFramework.Images;component/Common/PinMenuRight.png" Width="13" Style="{StaticResource DefaultIconStyle}"/>
                                            </RepeatButton>
                                            <!-- 
                                 This will present another "button" which will open up the Menu
                                 containing all TabItems, with the selected one being checked.
                                 Clicking an item here will select the respective TabItem.
                              -->
                                            <!--
                                            <Menu Background="Transparent">
                                                <MenuItem Style="{StaticResource TabMenuButtonStyle}"
                                           ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                AncestorType={x:Type TabControl}}, Path=Items}"
                                           ItemContainerStyle="{StaticResource TabMenuItem}">
                                                </MenuItem>
                                            </Menu>-->
                                        </StackPanel>
                                    </Grid>
                                    
                                    <!--<ad:DocumentTabPanel 
                                        x:Name="paneTabsPanel" 
                                        Panel.ZIndex ="1" 
                                        IsItemsHost="True" 
								        Margin="0,2,0,0"
                                        TabItemStyle="{StaticResource DocumentTabItemStyle}"/>-->
                                </DockPanel>
                            </Border>
                            <Grid Grid.Row="1" Margin="0,-1,0,0">
                                <Border 
                                    BorderThickness="5" 
                                    BorderBrush="#FFC1D2EE" 
                                    CornerRadius="3" 
                                    Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.Background}" Focusable="False"/>
                                <Border BorderThickness="2" BorderBrush="#FFD6E2F8" CornerRadius="3" Margin="1" Focusable="False">
                                    <ContentPresenter 
                                        ContentSource="SelectedContent"
                                        Margin="2"
								        KeyboardNavigation.TabNavigation="Local"
								        KeyboardNavigation.DirectionalNavigation="Contained"/>
                                </Border>
                            </Grid>                            
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>